package tpbox
{
	import flash.events.Event;
	
	import mx.containers.Canvas;

	public class MMDMLogo extends Canvas
	{
		private var oldX:Number = 0;
		private var oldY:Number = 0;
		
		private var randomX:Number;
		private var randomY:Number;
		
		private var up:Boolean = true;
		private var down:Boolean = true;
		
		public var color:Number = 0x00BB00;
		
		public function MMDMLogo()
		{
			//TODO: implement function
			super();
			this.addEventListener(Event.ENTER_FRAME,drawGraph);
		}
		
		override protected function initializationComplete():void
		{
			var oldX:Number = 0;
			var oldY:Number = Math.min((height/2),height);
		}
		
		private function drawGraph(event:Event):void
		{
			if( oldX == width){
				this.graphics.clear();
				oldX = 0;
				this.graphics.lineStyle(1,color);
				this.graphics.moveTo(oldX,oldY);
				up = true;
				down = true;
			}
			 // this is the small calculations to tell flash what the line should draw, you can change it a round do more simple or more complicated calculations.
			randomX = oldX + Math.random() * 2;
			randomY = (height/2) + ( Math.tan(oldY + Math.random() * 2) % (height / 6));
			
			randomX = Math.min(randomX,width);
			randomX = Math.max(0,randomX);
			
			if(up && randomX > (width * 7 / 16) ){
				randomY = 0 + (Math.random() % (height / 6 ) ); 
				up = false;
			}
			if(!up && down && randomX > (width * 9 / 16) ){
				randomY = height - (Math.random() % (height / 6 ) ); 
				down = false;
			}
						
			randomY = Math.min(randomY,height);
			randomY = Math.max(0,randomY);
			// and here we set it to draw the line, (finally).
			this.graphics.lineTo(randomX,randomY);
			oldX = randomX;
			oldY = randomY;
		}
		
	}
}